﻿using PSL.Lexer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSL
{
    public class PSLParameter : Dictionary<string, dynamic>
    {
        #region Private Member
        private PSLEngine runtime;
        private string functionName;
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Host"></param>
        /// <param name="Parser"></param>
        public PSLParameter(PSLEngine Runtime)
        {
            runtime = Runtime;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Check wether a query contains all given parameter
        /// </summary>
        /// <param name="ParameterName">Parametername</param>
        /// <returns></returns>
        public bool ContainsParameter(params string[] ParameterName)
        {
            bool cReturn = true;

            foreach (string cName in ParameterName)
            {
                if (!this.ContainsKey(cName))
                {
                    cReturn = false;
                    break;
                }
            }

            return cReturn;
        }

        /// <summary>
        /// Proof Parameter
        /// </summary>
        /// <param name="proofExactAmount">If set to true, the amount of parameter will be proofed</param>
        /// <param name="amount">Amount of parameter</param>
        /// <param name="throwException">Do throw exception</param>
        /// <param name="parameterName">List of parameter-names</param>
        /// <returns>True, if all parameter are given</returns>
        public bool ContainsParameter(bool throwException, params string[] parameterName)
        {
            bool returnValue = true;


            foreach (string cName in parameterName)
            {
                if (!this.ContainsKey(cName))
                {
                    returnValue = false;
                    if (throwException)
                    {
                        TokenizerHelper.HandleParameterMissingException(functionName, cName);
                    }
                }
            }

            foreach (var cName in this)
            {
                if (!parameterName.Contains(cName.Key))
                {
                    returnValue = false;
                    if (throwException)
                    {
                        TokenizerHelper.HandleInvalidParameterException(functionName, cName.Key);
                    }
                }
            }

            return returnValue;
        }
        #endregion

        #region Public Member
        /// <summary>
        /// Name of the function
        /// </summary>
        public string FunctionName
        {
            get { return functionName; }
            set { functionName = value; }
        }

        /// <summary>
        /// Instance of the current PSLScriptEngine
        /// </summary>
        public PSLEngine Runtime
        {
            get
            {
                return runtime;
            }
        }
        #endregion
    }
}
